package com.inspur.attendance.Service.ServiceImpl;

import com.inspur.attendance.Dao.UserDao;
import com.inspur.attendance.Entity.User;
import com.inspur.attendance.Service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    UserDao userInfoDao;

    @Override
    public boolean findUser(String username) {
        User byAccount = userInfoDao.findByAccount(username);
        if (byAccount != null) {
            return true;
        }else {
            return false;
        }
    }


    @Override
    public Integer loginAuth(String username, String password) {

        User byAccount = userInfoDao.findByAccount(username);

        User byAccountAndPassword = userInfoDao.findByAccountAndPassword(username, password);

        // 用户不存在 返回0
        if (byAccount == null) {
            return 0;
        }else {
            // 用户存在密码错误 返回2
            if (byAccountAndPassword == null) {
                return 2;
            } else {
                // 用户存在，且密码正确 返回1
                return 1;
            }
        }
    }
}
